package com.xy.annotaion.handler.kotlin.pdf

import com.itextpdf.io.IOException
import com.lowagie.text.*
import com.lowagie.text.pdf.PdfWriter
import com.xy.annotaion.handler.kotlin.p
import java.io.FileOutputStream

fun pm(img: Image) = p(img.url, img.width, img.height)

fun main() {
    println("Images")

    // step 1: creation of a document-object

    // step 1: creation of a document-object
    val document = Document()
    document.setMargins(0F, 0F, 0F, 0F)

    try {
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, FileOutputStream("Images.pdf"))

//        document.pageSize = Rectangle(10000F, 10000F)

        // step 3: we open the document
        document.open()

        // step 4:
        document.pageSize = PageSize.A10
        //不支持中文！！！
        document.newPage()
        document.add(Paragraph("A picture of my dog: otsoe.jpg"))


        val jpg: Image = Image.getInstance("readme/vim1.jpg")
        document.pageSize = Rectangle(jpg.width, jpg.height)
//        jpg.scalePercent(1000F, 1000F)
//        jpg.scaleAbsolute(jpg.width,jpg.height)
        document.newPage()
        document.add(jpg)
        pm(jpg)

//        document.pageSize = PageSize.A10
//        document.newPage()
//        document.add(Paragraph("getacro.gif"))
//
//        val gif: Image = Image.getInstance("readme/vim2.jpg")
//        document.pageSize = Rectangle(gif.width, gif.height)
//        document.newPage()
//        document.add(gif)
//        pm(gif)
//
//        document.pageSize = PageSize.A10
//        document.newPage()
//        document.add(Paragraph("pngnow.png"))
//
//        val png: Image = Image.getInstance("readme/vim3.jpg")
//        document.pageSize = Rectangle(png.width, png.height)
//        document.newPage()
//        document.add(png)
//        pm(png)
//
//        document.pageSize = PageSize.A10
//        document.newPage()
//        document.add(Paragraph("iText.bmp"))
//
//        val bmp: Image = Image.getInstance("readme/vim4.jpg")
//        document.pageSize = Rectangle(bmp.width, bmp.height)
//        document.newPage()
//        document.add(bmp)
//        pm(bmp)

    } catch (de: DocumentException) {
        System.err.println(de.message)
    } catch (ioe: IOException) {
        System.err.println(ioe.message)
    }

    // step 5: we close the document

    // step 5: we close the document
    document.close()
}